//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (C) 2007-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.

package cn.ekuma.epos.datalogic.define;

import java.util.List;

import cn.ekuma.data.dao.DataLogic;
import cn.ekuma.epos.datalogic.I_DataLogicAdmin;
import cn.ekuma.epos.datalogic.define.dao.ResourceDAO;
import cn.ekuma.epos.datalogic.define.dao.RoleDAO;
import cn.ekuma.epos.datalogic.define.dao.RoleInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.UserExtDAO;
import cn.ekuma.epos.security.dao.AppLockDAO;
import cn.ekuma.epos.security.dao.PermissionDAO;
import cn.ekuma.security.bean.I_Permission;
import cn.ekuma.security.datalogic.I_DataLogicSecurity;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;

/**
 *
 * @author adrianromero
 */
public class DataLogicAdmin extends DataLogic implements I_DataLogicAdmin,I_DataLogicSecurity {
    
    private UserExtDAO userDAO;
    private RoleDAO roleDAO;
    private RoleInfoDAO roleInfoDAO;
    private ResourceDAO resourceDAO;
    PermissionDAO rolePermissionDAO;
    private AppLockDAO appLockDAO;
    
    
    public DataLogicAdmin(I_Session s){
    	super(s);
        userDAO=new UserExtDAO(s);
        addDaoToMap(userDAO);
        roleDAO=new RoleDAO(s);
        addDaoToMap(roleDAO);
        roleInfoDAO=new RoleInfoDAO(roleDAO);
        addDaoToMap(roleInfoDAO);
        resourceDAO=new ResourceDAO(s);
        addDaoToMap(resourceDAO);
        rolePermissionDAO=new PermissionDAO(s);
        addDaoToMap(rolePermissionDAO);
        appLockDAO=new AppLockDAO(s);
        addDaoToMap(appLockDAO);
    }
	
	@Override
	public Class transParentClass(Class in) {
		return DateLogicUtils.transParentClass(in);
	}

	@Override
	public List<I_Permission> loadRolePermission(String roleId, String modeName) throws BasicException{
		
		return rolePermissionDAO.loadRolePermission(roleId,modeName) ;
	}

	@Override
	public boolean hasePermissionByRole(String roleId, String modeName,
			String permission) throws BasicException {
		return rolePermissionDAO.hasePermissionByRole(roleId,modeName,permission) ;
	}

	@Override
	public boolean hasePermissionByRole(String roleId, String modeName,
			String permission, String childPermission) throws BasicException {
		return rolePermissionDAO.hasePermissionByRole( roleId,  modeName,permission,  childPermission);
	}

	@Override
	public boolean lock(String askFor, String target, String targetId,
			String memo) {
		return appLockDAO.lock(askFor, target, targetId, memo);
	}

	@Override
	public boolean unlock(String askFor, String target, String targetId) {
		return appLockDAO.unlock(askFor, target, targetId);
	}

	@Override
	public boolean unlockAllbyAskToTarget(String askFor, String target) {
		return appLockDAO.unlockAllbyAskToTarget(askFor, target);
	}

	@Override
	public boolean unlockAllbyAsk(String askFor) {
		return appLockDAO.unlockAllbyAsk(askFor);
	}
}
